from info import  redies_store
from . import index_blu
from flask import render_template
from flask import current_app, session
from info.models import User

import logging

@index_blu.route("/")
def index():
    # 向redis里保存一个session
    # session["name"] = "zhangSaz n"
    # redies_store.set("inIndex", "redisok")
    # 测试日志文件
    # logging.debug("This is a debug log.")
    # logging.info("This is a info log.")
    # logging.warning("This is a warning log.")
    # logging.error("This is a error log.")
    # logging.critical("This is a critical log.")
    print("-------- in index ---------")
    user_id = session.get("user_id")
    print("user id is :", user_id)

    user_info = None
    if user_id:
        try:
            user = User.query.get(user_id)
            user_info = user.to_dict()
        except Exception as e:
            logging.error(e)

    return render_template("news/index.html", data={"user_info": user_info })


@index_blu.route("/favicon.ico")
def favicon():
    return current_app.send_static_file("news/favicon.ico")